// PROGRAMA : SISPM001(ENTRADA NO SISTEMA - MENU PRINCIPAL)
// BIBLIOTECA : SISP
// SISTEMA : SISP - SISTEMA DE INFORMACOES DE SEGURANCA PUBLICA
// CLIENTE : SECRETARIA DE SEGURAN�A PUBLICA
// PROGRAMADOR : EDU/FM DATA: 07/05/92
// OBJETIVO : MENU PRINCIPAL(ENTRADAS NO SISTEMA)
// ATUALIZACOES DATA: 27/08/1999
// PROGRAMA : SISPM001(ENTRADA NO SISTEMA - MENU PRINCIPAL)
// BIBLIOTECA : SISP
// SISTEMA : INFORMACOES DE SEGURANCA PUBLICA - SISP
// CLIENTE : SECRETARIA DE ESTADO DA SEGURAN�A CIDAD�
// PROGRAMADOR :
// OBJETIVO : DIVISAO DOS MODULOS, ALTERCAO DO MENU PRINCIPAL
// : INCLUSAO DO POSTO 2 DO JOAO PAULO EM 26/04/2000
// : INCLUSAO DO POSTO 5 DE IMPERATRIZ EM 18/08/2000
// : ESTE PROGRAMA FOI TOTALMENTE REESTRUTURADO
// OBS: ESTE PROGRAMA FOI REESTRUTURADO POR SOLON MIRANDA
package br.com.vti.sisp_sicrim.antigo.controller.programa;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;

import br.com.caelum.vraptor.Get;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Resource;
import br.com.caelum.vraptor.Result;
import br.com.vti.sisp_sicrim.antigo.controller.tela.Sisthm00;
import br.com.vti.sisp_sicrim.antigo.controller.tela.Sistm001;
import br.com.vti.sisp_sicrim.antigo.controller.tela.Sistm101;
import br.com.vti.sisp_sicrim.antigo.model.SicTabelas;
import br.com.vti.sisp_sicrim.antigo.model.Sislac01;
import br.com.vti.sisp_sicrim.antigo.model.Sisll001;
import br.com.vti.sisp_sicrim.antigo.model.Sislm001;
import br.com.vti.sisp_sicrim.antigo.util.ExceptionProgram;
import br.com.vti.sisp_sicrim.antigo.util.Scrg001;
import br.com.vti.sisp_sicrim.antigo.util.Sessao;
import br.com.vti.sisp_sicrim.antigo.util.Sisgsisp;
import br.com.vti.sisp_sicrim.antigo.util.UtilBean;

/**
 * Classe : Sispm001 OBJETIVO : MENU PRINCIPAL(ENTRADAS NO SISTEMA) *
 * 
 * @author Incode - Data: mai/2014
 * 
 */
@Resource
@Path("/antigo/sispm001")
public class Sispm001 {
	// Views utilizadas
	SicTabelas viu = new SicTabelas();
	SicTabelas vwTabele = new SicTabelas();
	// Telas/relatorios utilizados
	Sistm001 sistm001;
	Sistm101 sistm101;
	Sisthm00 sisthm00;
	// Includes utilizados
	Sislac01 sislac01 = new Sislac01();
	Sisll001 sisll001 = new Sisll001();
	Sislm001 sislm001 = new Sislm001();
	// Areas globais / session
	Sisgsisp sisgsisp;
	// Funcoes/subrotinas
	FuncoesGerais funcoes = new FuncoesGerais();

	Result result;
	Sessao sessao;
	private HttpSession httpSession;
	private ServletContext servletContext;
	Boolean primeiraVez = false;
	Sispm001 sispm001Anterior;
	String faseproc = "0";

	private String titul = "";
	private String[] tso = { "", "IDE", "ROU", "FUN", "", "", "", "", "", "", "", "", "", "", "" };
	private String[] tsd = { "", "IDENT. CIVIL", "ROUBO/FURTO", "FUNESP", "", "", "", "", "", "", "", "", "", "", "" };
	private String[] tdo = { "", "VEI", "CON", "MUL", "", "", "", "", "", "", "", "", "", "", "" };
	private String[] tdd = { "", "VEICULOS", "CONDUTORES", "MULTAS", "", "", "", "", "", "", "", "", "", "", "" };
	private String[] tzo = { "", "MSG", "SIS", "FIM", "", "", "", "", "", "", "", "", "", "", "" };
	private String[] tzd = { "", "MENSAGENS", "MENU SISTEMAS", "FINAL SERVICO", "", "", "", "", "", "", "", "", "", "", "" };
	private String[] tpo = { "", "PM ", "", "", "", "", "", "", "", "", "", "", "", "", "" };
	private String[] tpd = { "", "CONSULTAS", "", "", "", "", "", "", "", "", "", "", "", "", "" };
	private String[] teo = { "", "IPV", "", "", "", "", "", "", "", "", "", "", "", "", "" };
	private String[] ted = { "", "IPVA", "", "", "", "", "", "", "", "", "", "", "", "", "" };
	private String[] pmo = { "", "DEL", "", "", "", "", "", "", "", "", "", "", "", "", "" };
	private String[] pmd = { "", "MARANHAO", "", "", "", "", "", "", "", "", "", "", "", "", "" };
	// private String[][] screen = new String[13][80];
	// private String[] lets = { "", "  ^^^^^   ", "^^^     ^^", "^^^^      ",
	// "  ^^^^    ", "    ^^^^  ", "      ^^^ ", "       ^^^",
	// "^^   ^^^^ ", "  ^^^^    " };;
	// private String[] leti = { "", "^^^^^^^^^ ", "   ^^^    ", "   ^^^    ",
	// "   ^^^    ", "   ^^^    ", "   ^^^    ", "   ^^^    ",
	// "   ^^^    ", "^^^^^^^^^ " }; // private String[] letp = { "",
	// "^^^^^^^   ", "^^^   ^^^ ", "^^^    ^^^",
	// "^^^   ^^^ ", "^^^^^^^   ", "^^^       ", "^^^       ",
	// "^^^       ", "^^^       " };;
	private int lin = 9;
	private int[] col1 = { 0, 12, 28, 39, 55 };
	private int col = 0;
	private String titulo = "";
	private int i = 0;
	private int j = 0;
	private int w = 0;
	private String jUser = UtilBean.getInitUser();
	private String tabDescel = "";
	private int tPosto = 0;
	// CABECALHO DO POSTO: POSTO
	private String tAsterisco = "";
	// NUMERO DO POSTO
	private String tDescel = "";
	// CONTEM
	private String chaveAlfa = "";

	private Sistm001 preMapas() {
		sessao.setHttpSession(UtilBean.getSessao());
		sessao.setServletContext(UtilBean.getServletContext());
		sessao.setSisgsisp(new Sisgsisp());
		sessao.setScrg001(new Scrg001());
		sisthm00 = new Sisthm00(true, sessao);
		sistm001 = new Sistm001(true, sessao);
		sistm101 = new Sistm101(true, sessao);
		sistm001.setNomeClasse(this.getClass().getSimpleName().toUpperCase());
		// sistm001.setOperacao("IDE");
		sistm101.setProgram(this.getClass().getSimpleName().toUpperCase());
		sistm001.setDataCorrente(UtilBean.obtemDataDia());

		// SIMULA A DIGIRACAO DE UM ENTER
		// CHAMA MAPA COM O MENU PRINCIPAL DO SISP

		// MONTA CALENDARIO DO MES CORRENTE
		funcoes.sisnc001();
		sistm001.setMes(funcoes.mes);
		sistm001.setMesa(funcoes.dataL);
		return sistm001;
	}

	public Sispm001(Result result, Sessao sessao) {
		this.result = result;
		this.sessao = sessao;
	}

	@Post
	@Get
	public void executar(Sisthm00 sisthm00, Sistm001 sistm001, Sistm101 sistm101) {
		try {
			main(sisthm00, sistm001, sistm101);
		} catch (Exception e) {
			ExceptionProgram excp = new ExceptionProgram();
			excp.trataErroSiscerro(e, sessao, this.getClass().getSimpleName());
		}
	}

	private void main(Sisthm00 psisthm00, Sistm001 psistm001, Sistm101 psistm101) throws Exception {
		if (psistm001 == null && psisthm00 == null && psistm101 == null) {
			primeiraVez = true;
			sistm001 = preMapas();
			sistm001.setNavegar("../sispm001/executar");
			result.include("sistm101", sistm101);
			sessao.setAtributo("SISPM001", this);
			sistm101.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
			return;
		} else {
			restaurarEstados(psisthm00, psistm001, psistm101);
		}

		w = 0;
		// ATUALIZAR A TABELA DE USER-ID A CADA NOVO USUARIO
		chaveAlfa = UtilBean.moveSubstring(chaveAlfa, 0, 3, "N", 888);
		chaveAlfa = UtilBean.moveSubstring(chaveAlfa, 3, 14, "A", jUser);
		// TABELA DE USER-ID
		if (vwTabele.consultaTabcha(888, jUser)) {
			tabDescel = vwTabele.getDescricaoElem();

			if (UtilBean.getInitProgram().equals("NATPRO  ") && UtilBean.getInitUser().equals("S113590 ")) {
				sistm001.setP200("AMBIENTE DE PRODUCAO   !MUITO CUIDADO");
				sistm001.setCab01(UtilBean.subStr(tabDescel, 30, 30));
			} else {
				sistm001.setP200(UtilBean.subStr(tabDescel, 0, 30));
				sistm001.setCab01(UtilBean.subStr(tabDescel, 30, 30));
			}

			if (UtilBean.getInitUser().equals("T01327") || UtilBean.getInitUser().equals("T01328") || UtilBean.getInitUser().equals("T01329") || UtilBean.getInitUser().equals("T01330") || UtilBean.getInitUser().equals("T01331") || UtilBean.getInitUser().equals("G1138684") || UtilBean.getInitUser().equals("G1097427") || UtilBean.getInitUser().equals("G1098540") || UtilBean.getInitUser().equals("G1097708") || UtilBean.getInitUser().equals("G1097872") || UtilBean.getInitUser().equals("G1096841") || UtilBean.getInitUser().equals("G1097666") || UtilBean.getInitUser().equals("S1098862") || UtilBean.getInitUser().equals("G1097294") || UtilBean.getInitUser().equals("G1097443") || UtilBean.getInitUser().equals("G1293372") || UtilBean.getInitUser().equals("S1098151") || UtilBean.getInitUser().equals("G1098557") || UtilBean.getInitUser().equals("S1098631") || UtilBean.getInitUser().equals("G1128057") || UtilBean.getInitUser().equals("T01295") || UtilBean.getInitUser().equals("T01296") || UtilBean.getInitUser().equals("T01297") || UtilBean.getInitUser().equals("S1098631") || UtilBean.getInitUser().equals("T01296") || UtilBean.getInitUser().equals("T01297") || UtilBean.getInitUser().equals("S1098631")) {
				sistm001.setOperacao("DEL");
				// || .equals("G1098540'
				// return;
			}
		}
		vwTabele.fecha();
		if (vwTabele.registrosProcessados() == 0) {
			sistm101.setMensagem("USUARIO NAO AUTORIZADO PARA USAR O SISP:" + UtilBean.subStr(chaveAlfa, 3, 14));
			sistm101.setMensagem(sistm101.getMensagem() + "<br>=> FAVOR ENTRAR EM CONTATO COM O ANALISTA DO SISTEMA SISP");
			sistm101.setMensagem(sistm101.getMensagem() + "<br>---------------------------------------------------------");
			sistm101.setMensagem(sistm101.getMensagem() + "<br>ANALISTA DO SISP: SOLON OU PINHO");
			sistm101.setMensagem(sistm101.getMensagem() + "<br>TEL: 0800-2841417 OU 3218-2137");
			result.include("sistm101", sistm101);
			sessao.setAtributo("SISPM001", this);
			sistm101.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
			return;
		}
		sistm101.setMensagem("");
		if (faseproc.equals("1")) {
			sisthm00.receberTela(false, result);
			if (sisthm00.getOperacao().trim().equals("")) {
				sistm001.setMensagemSaida("INFORME O MODULO DESEJADO");
			}
			sistm001.setOperacao(sisthm00.getOperacao());
			faseproc = "0";
			sessao.setAtributo("SISPM001", this);
			result.include("sistm001", sistm001);
			sistm001.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
			return;
		}

		if (psistm001 == null && psistm101 != null) {
			sessao.setAtributo("SISPM001", this);
			result.include("sistm001", sistm001);
			sistm001.enviarTela(true, result, getClass().getSimpleName().toUpperCase());
			return;
		} else {
			sistm001.receberTela(false, result);
		}

		if (sistm001.getOperacao().trim().equals("")) {
			switch (sistm001.getCamtela()) {
			case 8026: { // 8026: {
				sisthm00.setTitulo("GEJUSPC");
				for (i = 2; i <= 5; i++) {
					for (j = 1; j <= 2; j++) {
						w += 1;
						sisthm00.setOp9(j, i, tso[w]);
						sisthm00.setDe9(j, i, tsd[w]);
					}
				}
				break;
			}
			case 8049: {// case 8049: {
				sisthm00.setTitulo(" INFORMACOES ");
				sisthm00.setOp9(1, 3, "INF");
				sisthm00.setDe9(1, 3, "CONSULTA MODULOS");
				break;
			}
			case 10026: {// case 10026: {
				sisthm00.setTitulo(" SEFAZ ");
				for (i = 3; i <= 5; i++) {
					for (j = 1; j <= 2; j++) {
						w += 1;
						sisthm00.setOp9(j, i, teo[w]);
						sisthm00.setDe9(j, i, ted[w]);
					}
				}
				break;
			}
			case 10049: { // case 10049: {
				sisthm00.setTitulo(" PROC. BATCH ");
				sisthm00.setOp9(1, 3, "BAT");
				sisthm00.setDe9(1, 3, "PROCESSOS BATCH");
				break;
			}
			case 12026: { // 12026: {
				sisthm00.setTitulo(" DETRAN ");
				for (i = 3; i <= 5; i++) {
					for (j = 1; j <= 2; j++) {
						w += 1;
						sisthm00.setOp9(j, i, tdo[w]);
						sisthm00.setDe9(j, i, tdd[w]);
					}
				}
				break;
			}
			case 12049: { // case 12049: {
				sisthm00.setTitulo(" DIVERSOS ");
				for (i = 3; i <= 5; i++) {
					for (j = 1; j <= 2; j++) {
						w += 1;
						sisthm00.setOp9(j, i, tzo[w]);
						sisthm00.setDe9(j, i, tzd[w]);
					}
				}
				break;
			}
			case 14026: { // case 14026: {
				sisthm00.setTitulo(" P. MILITAR ");
				for (i = 3; i <= 5; i++) {
					for (j = 1; j <= 2; j++) {
						w += 1;
						sisthm00.setOp9(j, i, tpo[w]);
						sisthm00.setDe9(j, i, tpd[w]);
					}
				}
				break;
			}
			case 14049: { // case 14049: {
				sisthm00.setTitulo("DELEGADOS(AS)");
				for (i = 3; i <= 5; i++) {
					for (j = 1; j <= 2; j++) {
						w += 1;
						sisthm00.setOp9(j, i, pmo[w]);
						sisthm00.setDe9(j, i, pmd[w]);
					}
				}
				break;
			}
			default: {
				sistm001.setMensagemSaida("INFORME O MODULO");
				sessao.setAtributo("SISPM001", this);
				result.include("sistm001", sistm001);
				sistm001.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}
			}

			w = 0;
			faseproc = "1";
			sessao.setAtributo("SISPM001", this);
			result.include("sisthm00", sisthm00);
			sisthm00.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
			return;
		}

		if (!sistm001.getOperacao().trim().equals("")) {
			if (sistm001.getOperacao().equals("FIM")) {
				// PENDENCIA CALL 'X'
			}
			if (sistm001.getOperacao().equals("SIS")) {
				return; // Encerrar
			}
			vwTabele.pesq = UtilBean.moveSubstring(vwTabele.pesq, 0, 3, "N", 18);
			vwTabele.pesq = UtilBean.moveSubstring(vwTabele.pesq, 3, 12, "N", sistm001.getMatric());
			sislac01.niveis = "";
			if (vwTabele.consultaTabele(18, (long) sistm001.getMatric())) {
				// 399
				sislac01.niveis = vwTabele.getDescricaoElem();
				if (!sistm001.getSenha().trim().toUpperCase().equals(vwTabele.getChaveAlfaAcesso().trim().toUpperCase())) {
					sistm001.enviarMensagem("senha", "Senha Inv�lida!");
					sessao.setAtributo("SISPM001", this);
					result.include("sistm001", sistm001);
					sistm001.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
					return;
				}
				if (!sistm001.getNsenha().trim().equals("")) {
					nvsenha();
					sessao.setAtributo("SISPM001", this);
					result.include("sistm001", sistm001);
					sistm001.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
					return;
				}
			}
			vwTabele.fecha();
			if (vwTabele.registrosProcessados() == 0) {
				sistm001.enviarMensagem("matric", "Matricula Inv�lida!");
				sessao.setAtributo("SISPM001", this);
				result.include("sistm001", sistm001);
				sistm001.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}
		}
		if (UtilBean.funcao.equals(UtilBean.ctt_retorna)) {
			sessao.setAtributo("SISPM001", this);
			result.include("sistm001", sistm001);
			sistm001.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
			return;
		}
		if (!sistm001.getNsenha().trim().equals("")) {
			sistm001.receberTela(false, result);
		}

		switch (sistm001.getOperacao().trim().toUpperCase()) {
		case "VEI": {
			if (!UtilBean.getInitUser().startsWith("D") && !UtilBean.getInitUser().startsWith("R") && !UtilBean.getInitUser().startsWith("S") && !UtilBean.getInitUser().startsWith("T")) {
				sistm001.enviarMensagem(null, "");
				sessao.setAtributo("SISPM001", this);
				result.include("sistm001", sistm001);
				sistm001.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}
			if (UtilBean.subStr(sislac01.niveis, 30 + 2 - 1, 1).equals("0")) {
				sistm001.enviarMensagem("senha", "");
				sessao.setAtributo("SISPM001", this);
				result.include("sistm001", sistm001);
				sistm001.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}
			Veipm001 veipm001 = new Veipm001(result, sessao);
			veipm001.executar(null);
			return;
		}
		case "CON": {
			if (!UtilBean.getInitUser().startsWith("D") && !UtilBean.getInitUser().startsWith("R") && !UtilBean.getInitUser().startsWith("S") && !UtilBean.getInitUser().startsWith("T")) {
				sistm001.enviarMensagem(null, "");
				sessao.setAtributo("SISPM001", this);
				result.include("sistm001", sistm001);
				sistm001.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}
			if (UtilBean.subStr(sislac01.niveis, 30 + 3 - 1, 1).equals("0")) {
				sistm001.enviarMensagem("senha", "");
				sessao.setAtributo("SISPM001", this);
				result.include("sistm001", sistm001);
				sistm001.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}
			Rchpm001 rchpm001 = new Rchpm001(result, sessao);
			rchpm001.executar(null);
			return;
		}
		case "ROU": {
			if (!UtilBean.getInitUser().startsWith("D") && !UtilBean.getInitUser().startsWith("R") && !UtilBean.getInitUser().startsWith("S") && !UtilBean.getInitUser().startsWith("T")) {
				sistm001.enviarMensagem(null, "");
				sessao.setAtributo("SISPM001", this);
				result.include("sistm001", sistm001);
				sistm001.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}
			if (UtilBean.subStr(sislac01.niveis, 30 + 7 - 1, 1).equals("0")) {
				sistm001.enviarMensagem("senha", "");
				sessao.setAtributo("SISPM001", this);
				result.include("sistm001", sistm001);
				sistm001.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}
			Roupm001 roupm001 = new Roupm001(result, sessao);
			roupm001.executar(null);
			return;
		}
		case "IDE": {
			if (!UtilBean.getInitUser().startsWith("D") && !UtilBean.getInitUser().startsWith("R") && !UtilBean.getInitUser().startsWith("S") && !UtilBean.getInitUser().startsWith("T") && !UtilBean.getInitUser().startsWith("B") && !UtilBean.getInitUser().startsWith("G")) {
				sistm001.enviarMensagem(null, "");
				sessao.setAtributo("SISPM001", this);
				result.include("sistm001", sistm001);
				sistm001.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}
			if (UtilBean.subStr(sislac01.niveis, 30 + 13 - 1, 1).equals("0")) {
				sistm001.enviarMensagem("senha", "");
				sessao.setAtributo("SISPM001", this);
				result.include("sistm001", sistm001);
				sistm001.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}
			Idcpm001 idcpm001 = new Idcpm001(result, sessao);
			idcpm001.executar(null);
			return;
		}
		case "FUN": {
			if (!UtilBean.getInitUser().startsWith("D") && !UtilBean.getInitUser().startsWith("R") && !UtilBean.getInitUser().startsWith("S") && !UtilBean.getInitUser().startsWith("T")) {
				sistm001.enviarMensagem(null, "");
				sessao.setAtributo("SISPM001", this);
				result.include("sistm001", sistm001);
				sistm001.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}
			if (UtilBean.subStr(sislac01.niveis, 30 + 15 - 1, 1).equals("0")) {
				sistm001.enviarMensagem("senha", "");
				sessao.setAtributo("SISPM001", this);
				result.include("sistm001", sistm001);
				sistm001.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}
			Funpm001 funpm001 = new Funpm001(result, sessao);
			funpm001.executar(null);
			return;
		}
		case "IPV": {
			if (!UtilBean.getInitUser().startsWith("D") && !UtilBean.getInitUser().startsWith("R") && !UtilBean.getInitUser().startsWith("S") && !UtilBean.getInitUser().startsWith("T")) {
				sistm001.enviarMensagem(null, "");
				sessao.setAtributo("SISPM001", this);
				result.include("sistm001", sistm001);
				sistm001.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}
			if (UtilBean.subStr(sislac01.niveis, 30 + 6 - 1, 1).equals("0")) {
				sistm001.enviarMensagem("senha", "");
				sessao.setAtributo("SISPM001", this);
				result.include("sistm001", sistm001);
				sistm001.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}
			Ipvpm001 ipvpm001 = new Ipvpm001(result, sessao);
			ipvpm001.executar(null);
			return;
		}
		case "MSG": {
			sistm001.setOperacao("MSG");
			Msgpm001 msgpm001 = new Msgpm001(result, sessao);
			msgpm001.executar(null, null, null);
			return;
		}
		case "MUL": {
			// if (!UtilBean.getInitUser().startsWith("D") && !UtilBean.getInitUser().startsWith("R") && !UtilBean.getInitUser().startsWith("S") && !UtilBean.getInitUser().startsWith("T")) {
			// sistm001.enviarMensagem(null, "");
			// sessao.setAtributo("SISPM001", this);
			// result.include("sistm001", sistm001);
			// sistm001.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
			// return;
			// }
			// if (UtilBean.subStr(sislac01.niveis, 30 + 4 - 1, 1).equals("0")) {
			// sistm001.enviarMensagem("senha", "");
			// sessao.setAtributo("SISPM001", this);
			// result.include("sistm001", sistm001);
			// sistm001.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
			// return;
			// }
			// Mulpm001 mulpm001 = new Mulpm001(result, sessao);
			// mulpm001.executar(null);
			// return;
		}
		case "DEL": {
			if (!UtilBean.getInitUser().startsWith("D") && !UtilBean.getInitUser().startsWith("R") && !UtilBean.getInitUser().startsWith("S") && !UtilBean.getInitUser().startsWith("T") && !UtilBean.getInitUser().startsWith("G")) {
				sistm001.enviarMensagem(null, "");
				sessao.setAtributo("SISPM001", this);
				result.include("sistm001", sistm001);
				sistm001.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}
			if (UtilBean.subStr(sislac01.niveis, 30 + 13 - 1, 1).equals("0")) {
				sistm001.enviarMensagem("senha", "");
				sessao.setAtributo("SISPM001", this);
				result.include("sistm001", sistm001);
				sistm001.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}
			Idcpcc01 idcpcc01 = new Idcpcc01(result, sessao);
			idcpcc01.executar(null, null);
			return;
		}
		case "PM": {
			if (!UtilBean.getInitUser().startsWith("D") && !UtilBean.getInitUser().startsWith("R") && !UtilBean.getInitUser().startsWith("S") && !UtilBean.getInitUser().startsWith("T")) {
				sistm001.enviarMensagem(null, "");
				sessao.setAtributo("SISPM001", this);
				result.include("sistm001", sistm001);
				sistm001.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}
			if (UtilBean.subStr(sislac01.niveis, 30 + 8 - 1, 1).equals("0")) {
				sistm001.enviarMensagem("senha", "");
				sessao.setAtributo("SISPM001", this);
				result.include("sistm001", sistm001);
				sistm001.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}
			Pmmpm001 pmmpm001 = new Pmmpm001(result, sessao);
			pmmpm001.executar(null);
			return;
		}
		case "INF": {
			if (UtilBean.subStr(sislac01.niveis, 30 + 9 - 1, 1).equals("0")) {
				sistm001.enviarMensagem("senha", "");
				sessao.setAtributo("SISPM001", this);
				result.include("sistm001", sistm001);
				sistm001.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}
			Infpm001 infpm001 = new Infpm001(result, sessao);
			infpm001.executar(null);
			return;
		}
		case "BAT": {
			if (UtilBean.subStr(sislac01.niveis, 30 + 20 - 1, 1).equals("0")) {
				sistm001.enviarMensagem("senha", "");
				sessao.setAtributo("SISPM001", this);
				result.include("sistm001", sistm001);
				sistm001.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}
			Batpm001 batpm001 = new Batpm001(result, sessao);
			batpm001.executar(null);
			return;
		}
		case "VIS": {
			// if (!UtilBean.getInitUser().startsWith("D") && !UtilBean.getInitUser().startsWith("R") && !UtilBean.getInitUser().startsWith("S") && !UtilBean.getInitUser().startsWith("T")) {
			// sistm001.enviarMensagem(null, "");
			// sessao.setAtributo("SISPM001", this);
			// result.include("sistm001", sistm001);
			// sistm001.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
			// return;
			// }
			// if (UtilBean.subStr(sislac01.niveis, 30 + 9 - 1, 1).equals("0")) {
			// sistm001.enviarMensagem("senha", "");
			// sessao.setAtributo("SISPM001", this);
			// result.include("sistm001", sistm001);
			// sistm001.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
			// return;
			// }
			// VER vispm001();
			break;
		}
		case "FIM": {
			// PENDENCIA CALL 'X' - COBOL
			break;
		}
		default: {
			sistm001.enviarMensagem(null, "");
			sessao.setAtributo("SISPM001", this);
			result.include("sistm001", sistm001);
			sistm001.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
			return;
		}
		}
		sessao.setAtributo("SISPM001", this);
		result.include("sistm001", sistm001);
		sistm001.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
	}

	private boolean nvsenha() {
		// if (!UtilBean.funcao.equals(UtilBean.ctt_proxima)) {
		// sistm001.enviarMensagem(null, "TECLE PF-8 PARA ALTERAR SUA SENHA");
		// return;
		// }

		titul = "REDIGITE";

		// sistm001.enviarReceberTela(false, result);
		if (UtilBean.funcao.equals(UtilBean.ctt_retorna)) {
			return false;
		}
		if (sistm001.getSen1().trim().equals("")) {
			sistm001.enviarMensagem("sen1", "REDIGITE A NOVA SENHA");
			return false;
		}
		if (!sistm001.getSen1().trim().toUpperCase().equals(sistm001.getNsenha().trim().toUpperCase())) {
			sistm001.enviarMensagem("sen1", "NOVA SENHA NAO CONFERE, INFORME NOVAMENTE");
			return false;
		}
		viu.consultaTabele(18, (long) sistm001.getMatric());
		// 399
		viu.setChaveAlfaAcesso(sistm001.getNsenha().toUpperCase());
		viu.atualiza();
		viu.fecha();
		// dao.commit();

		// dao.rollback();
		sistm001.enviarMensagem("nsenha", "SENHA ALTERADA");
		sistm001.setNsenha("");
		sistm001.setSen1("");
		return true;
	}

	private void restaurarEstados(Sisthm00 psisthm00, Sistm001 psistm001, Sistm101 psistm101) {
		this.sispm001Anterior = (Sispm001) sessao.getAtributo("SISPM001");
		if (psisthm00 != null) {
			sisthm00 = psisthm00;
			sisthm00.setOp9(this.sispm001Anterior.sisthm00.getOp9());
			sisthm00.setDe9(this.sispm001Anterior.sisthm00.getDe9());
			sisthm00.setEmpresa(sessao.getSisgsisp().getEmpresa());
			sisthm00.setVersao(sessao.getSisgsisp().getVersao());
		} else {
			sisthm00 = this.sispm001Anterior.sisthm00;
		}
		sisthm00.setSessao(sessao);
		if (psistm001 != null) {
			sistm001 = psistm001;
			sistm001.setEmpresa(sessao.getSisgsisp().getEmpresa());
			sistm001.setVersao(sessao.getSisgsisp().getVersao());
		} else {
			sistm001 = this.sispm001Anterior.sistm001;
		}
		sistm001.setSessao(sessao);
		if (psistm101 != null) {
			sistm101 = psistm101;
			sistm101.setEmpresa(sessao.getSisgsisp().getEmpresa());
			sistm101.setVersao(sessao.getSisgsisp().getVersao());
		} else {
			sistm101 = this.sispm001Anterior.sistm101;
		}
		sistm001.setSessao(sessao);

		// MONTA CALENDARIO DO MES CORRENTE
		funcoes.sisnc001();
		sistm001.setMes(funcoes.mes);
		sistm001.setMesa(funcoes.dataL);
		this.faseproc = this.sispm001Anterior.faseproc;
	}
}
